package com.example.hibernate.core;

import java.util.ArrayList;
import java.util.List;

import com.example.hibernate.pojos.ITableObject;
import com.example.hibernate.pojos.IUserOperation;
import com.example.hibernate.utils.AllWhereClause;

public class TalkToDB {

	private static TalkToDB _instance = null;
	
	private TalkToDB(){
		
	}
	
	public static TalkToDB getInstance(){
		if(_instance == null)
			_instance = new TalkToDB();
		return _instance;
	}
	
	
	public ITableObject getUserPasswordForUserName(String userName){
		List<Object> l = new ArrayList<Object>();
		l.add(userName);
		return HibernateCommunicator.getInstance().readSingleRecord(AllWhereClause.GET_USER_DETAILS_FROM_USERNAME, l);
	}
	
	public void addUserLogin(IUserOperation uo){
		HibernateCommunicator.getInstance().insertNewRecord(uo);
	}
	
	public int isTheUserAlreadyLoggedIn(String userName){
		List<Object> l = new ArrayList<Object>();
		l.add(userName);
//		Object ito = HibernateCommunicator.getInstance().readSingleRecord(AllWhereClause.GET_LAST_OPERATION_TIME_USER, l);
		l.add(userName);
		IUserOperation uo = (IUserOperation)HibernateCommunicator.getInstance().readSingleRecord(AllWhereClause.GET_LAST_USER_OPERATION, l);
		return uo.getLoginStatus();
	}
}
